package game.game.testing;

import com.crunch.math.Vector2f;
import com.crunch.physics.CategoryMask;
import com.crunch.physics.DynamicPhysicsEntity;
import com.crunch.physics.PhysicsProximityZone;
import game.game.GameActor;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * A test physics proximity zone.
 */
public class TestProximityZone extends GameActor {
	public void initState(JSONObject state)
			throws JSONException {
	}

	public void onGameActorDestroy() {
		if (entity != null) {
			entity.remove();
			entity = null;
		}
	}

	public void loadState(JSONObject state)
			throws JSONException {
		PhysicsProximityZone.Description desc = new PhysicsProximityZone.Description();
		desc.shape = PhysicsProximityZone.Shape.RECTANGLE;
		desc.boundMin = new Vector2f(4.0f, 4.0f);
		desc.boundMax = new Vector2f(6.0f, 7.0f);
		desc.center = new Vector2f(4.0f, 4.0f);
		desc.radius = 1.0f;
		desc.categoryMask = CategoryMask.addCategoryToMask(CategoryMask.MASK_NO_CATEGORIES, 0);
		desc.data = this;
		desc.eventHandler = new PhysicsProximityZone.EventHandler() {
			@Override
			public void onIntersect(PhysicsProximityZone proximityZone, DynamicPhysicsEntity entity) {}

			@Override
			public void onEnter(PhysicsProximityZone proximityZone, DynamicPhysicsEntity entity) {
				System.out.println(entity + " entered " + proximityZone);
			}

			@Override
			public void onExit(PhysicsProximityZone proximityZone, DynamicPhysicsEntity entity) {
				System.out.println(entity + " exited " + proximityZone);
			}
		};
		entity = getRoomState().getPhysicsSimulation().addProximityZone(desc);
	}

	public JSONObject saveState()
			throws JSONException {
		// ...
		return null;
	}

	private PhysicsProximityZone entity;
}
